/*
 * TestMP.java
 *
 * Created on 12. Dezember 2006, 11:55
 *
 * Test: Using the JXML2OWL API
 * http://jxml2owl.projects.semwebcentral.org/jxml2owlapi/quickstart.html
 * Madeira University, http://www.uma.pt
 */

package de.dfki.dmas.owls2wsdl.grounding;

import uma.pfc.jxml2owl.XML2OWL;
import uma.pfc.jxml2owl.model.ClassAssociation;
import uma.pfc.jxml2owl.model.MappingProject;
import uma.pfc.jxml2owl.xslt.XSLTCreator;

/**
 *
 * @author Oliver Fourman
 */
public class TestMP {
    
    /** Creates a new instance of TestMP */
    public TestMP() {
    }
    
    public void example1() {
        //Creates the new Mapping Project
        MappingProject mp = XML2OWL.createMappingProject();
        //Loads the OWL ontology and XML Schema
        try {
          //When loading an OWL ontology, a prefix must be specified.
          //This prefix can then be used to address OWL resources defined by the loaded ontology.
          mp.loadOWLFile("http://jxml2owl.projects.semwebcentral.org/sample/tourism.owl", "tourism");
          mp.loadXMLFile("http://jxml2owl.projects.semwebcentral.org/sample/XMLTourism.xsd");
        }
        catch(Exception e) {
          e.printStackTrace();
        }

        //Creates the mappings
        ClassAssociation airPlaneTrip1 = mp.addClassAssociation(
              "http://jxml2owl.projects.semwebcentral.org/sample/tourism.owl#AirplaneTrip",
              "/thing/airplannetrip", 
              "/thing/airplannetrip");  

        ClassAssociation location1 = mp.addClassAssociation(
              "tourism:Location", 
              "/thing/airplannetrip/trips/startpoint",
              "/thing/airplannetrip/trips/startpoint");

        ClassAssociation location2 = mp.addClassAssociation(
              "tourism:Location", 
              "/thing/airplannetrip/trips/endpoint",
              "/thing/airplannetrip/trips/endpoint");

        ClassAssociation city1 = mp.addClassAssociation(
              "tourism:City", 
              "/thing/airplanneTrip/trips/startpoint",
              "/thing/airplanneTrip/trips/startpoint");

        ClassAssociation city2 = mp.addClassAssociation(
              "tourism:City", 
              "/thing/airplanneTrip/trips/endpoint",
              "/thing/airplanneTrip/trips/endpoint");      
      
        mp.addObjectPropertyAssociation("tourism:city", location1, city1);
        mp.addObjectPropertyAssociation("tourism:city", location2, city2);
        
        mp.addDatatypePropertyAssociation(
                "tourism:date", 
                airPlaneTrip1, 
                "/thing/airplannetrip/date");
                
        mp.addDatatypePropertyAssociation(
                "tourism:city_name",
                city1,
                "/thing/airplannetrip/trips/startpoint");
        
        mp.addDatatypePropertyAssociation(
                "tourism:city_name",
                city2,
                "/thing/airplannetrip/trips/endpoint");

        ClassAssociation hotel1 = mp.addClassAssociation(
                "tourism:Hotel",
                "/thing/hotel",
                "/thing/hotel");
        
        ClassAssociation room1 = mp.addClassAssociation(
                "tourism:Room",
                "/thing/hotel/room",
                "/thing/hotel/room");
        
        mp.addObjectPropertyAssociation("tourism:rooms",                    hotel1, room1);
        mp.addDatatypePropertyAssociation("tourism:hotel_name",             hotel1, "/thing/hotel/hotel_name");
        mp.addDatatypePropertyAssociation("tourism:classification_in_stars",hotel1, "/thing/hotel/classification_in_stars");

        mp.addDatatypePropertyAssociation("tourism:has_tv",         room1, "/thing/hotel/room/has_tv");
        mp.addDatatypePropertyAssociation("tourism:type",           room1, "/thing/hotel/room/type");
        mp.addDatatypePropertyAssociation("tourism:has_mini_bar",   room1, "/thing/hotel/room/has_mini_bar");
        

        ClassAssociation location3 = mp.addClassAssociation(
                "tourism:Location",
                "/thing/hotel/accommodation/location",
                "/thing/hotel/accommodation/location");

        mp.addObjectPropertyAssociation("tourism:location", hotel1, location3);

        ClassAssociation country1 = mp.addClassAssociation(
                "tourism:Country",
                "/thing/hotel/accommodation/location/country",
                "/thing/hotel/accommodation/location/country/country_name");
        
        mp.addObjectPropertyAssociation("tourism:country", location3, country1);

        mp.addDatatypePropertyAssociation("tourism:country_name", country1,
              "/thing/hotel/accommodation/location/country/country_name");

        ClassAssociation city3 = mp.addClassAssociation("tourism:City",
              "/thing/hotel/accommodation/location/country/city",
              "/thing/hotel/accommodation/location/country/city/city_name");
        mp.addObjectPropertyAssociation("tourism:city", location3,
              city3);
        mp.addDatatypePropertyAssociation("tourism:city_name", city3,
              "/thing/hotel/accommodation/location/country/city/city_name");

        mp.addDatatypePropertyAssociation("tourism:address", location3,
              "/thing/hotel/accommodation/location/address");

        mp.addObjectPropertyAssociation("tourism:cities", country1, city3);

        //Generates the XSLT
        XSLTCreator xsltCreator = XSLTCreator.getXSLTCreator(mp, XSLTCreator.SPEC_ID);
        
        try {
            xsltCreator.createXSLT();

            //Saves the XSLT
            xsltCreator.saveXSLT("file:/D:/tmp/xslt.xsl");

            //Saves the project
            mp.saveProject("file:/D:/tmp/save.xml");
            //resumes the saved project
            //mp.loadProject("D:\\save.xml");
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
    
    public void example2() {
        try {
            MappingProject mp = XML2OWL.restoreMappingProject("C:\\lib\\jxml2owl-0.91\\JXML2OWLMapper\\sample\\teacher\\teacher_project.xml");
            XSLTCreator xsltCreator = XSLTCreator.getXSLTCreator(mp, XSLTCreator.SPEC_ID);
            xsltCreator.createXSLT();
            xsltCreator.saveXSLT("file:/C:/lib/jxml2owl-0.91/JXML2OWLMapper/sample/teacher/xslt.xsl");
        }
        catch(Exception e) {
            e.printStackTrace();
        }
        
    }
    
    public void example3() throws Exception {
        MappingProject mp = XML2OWL.createMappingProject();
        mp.loadOWLFile("http://jxml2owl.projects.semwebcentral.org/sample/tourism.owl", "tourism");
        
        mp.loadXMLFile("file:///C:/lib/jxml2owl-0.91/JXML2OWLMapper/sample/tourism/mytourism.xsd");
        ClassAssociation city = mp.addClassAssociation(
              "http://jxml2owl.projects.semwebcentral.org/sample/tourism.owl#City",
              "/city", 
              "/city");
        mp.addDatatypePropertyAssociation("tourism:city_name", city,
              "/city/city_name");
        
        XSLTCreator xsltCreator = XSLTCreator.getXSLTCreator(mp, XSLTCreator.SPEC_ID);
        xsltCreator.createXSLT();
        System.out.println("OUTPUT: "+xsltCreator.getXSLTAsString());
        //xsltCreator.saveXSLT("file:/C:/lib/jxml2owl-0.91/JXML2OWLMapper/sample/teacher/myxslt.xsl");
        
    }
    
    public static void main(String[] args) {
        TestMP mp = new TestMP();
        //mp.example1();
        //mp.example2();
        try {
            mp.example1();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
        
        
    }
    
}
